//
//  ReportCardProblemHeaderView.m
//  jzyParents
//
//  Created by 任辰东 on 2022/8/23.
//

#import "ReportCardProblemHeaderView.h"
#import "UIButton+TouchAreaInsets.h"

@interface ReportCardProblemHeaderView ()
@property (nonatomic, strong) UIView *bottomView;
@property (nonatomic, strong) UIView *lineView;
@property (nonatomic, strong) UILabel *infoLabel;
@property (nonatomic, strong) UIView *line;
@property (nonatomic, strong) UIView *markView;
@property (nonatomic, strong) UILabel *markLabel;
@property (nonatomic, strong) UIButton *cardBtn;
@property (nonatomic, strong) UIButton *detailBtn;

@property (nonatomic, strong) UILabel *label1;
@property (nonatomic, strong) UILabel *label2;
@property (nonatomic, strong) UILabel *label3;
@property (nonatomic, strong) UILabel *label4;
@property (nonatomic, strong) UILabel *label5;
@end

@implementation ReportCardProblemHeaderView

-(void)cardBtnAction
{
    if (self.CardBlock) {
        self.CardBlock();
    }
}

-(void)detailBtnAction
{
    if (self.DetailBlock) {
        self.DetailBlock();
    }
}

-(void)configViewWithTitle:(NSString *)title
{
    self.infoLabel.text = title;
}

-(void)setupViews
{
    self.backgroundColor = UIColorFromHex(kColorBG);
    [self addSubview:self.bottomView];
    [self.bottomView addSubview:self.lineView];
    [self.bottomView addSubview:self.infoLabel];
    [self.bottomView addSubview:self.line];
    [self.bottomView addSubview:self.markView];
    [self.bottomView addSubview:self.markLabel];
    [self.bottomView addSubview:self.cardBtn];
    [self.bottomView addSubview:self.detailBtn];
    [self.bottomView addSubview:self.label1];
    [self.bottomView addSubview:self.label2];
    [self.bottomView addSubview:self.label3];
    [self.bottomView addSubview:self.label4];
    [self.bottomView addSubview:self.label5];

    
    self.infoLabel.text = @"  ";
    self.markLabel.text = @"小题分统计";
    
    [self.cardBtn addTarget:self action:@selector(cardBtnAction) forControlEvents:UIControlEventTouchUpInside];
    [self.detailBtn addTarget:self action:@selector(detailBtnAction) forControlEvents:UIControlEventTouchUpInside];
    
    [self.cardBtn setTouchAreaInsets:UIEdgeInsetsMake(10, 15, 10, 0)];
    [self.detailBtn setTouchAreaInsets:UIEdgeInsetsMake(15, 15, 10, 15)];
    
    self.cardBtn.hidden = YES;
    self.detailBtn.hidden = YES;
}

-(void)setupLayout
{
    
    [self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.edges.equalTo(self);
    }];
    
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.right.top.equalTo(self.bottomView).offset(0);
        make.height.mas_equalTo(10);
    
    }];
    
    [self.infoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(self.lineView.mas_bottom).offset(15);
        make.left.equalTo(self.bottomView).offset(15);
    
    }];
    
    [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(self.infoLabel.mas_bottom).offset(15);
        make.left.equalTo(self.bottomView).offset(15);
        make.right.equalTo(self.bottomView).offset(-15);
        make.height.mas_equalTo(kOnePixel);
    }];
    
    [self.markView mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(self.line.mas_bottom).offset(20);
        make.left.equalTo(self.bottomView).offset(15);
        make.height.mas_equalTo(13);
        make.width.mas_equalTo(4);
    }];
    
    [self.markLabel mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.centerY.equalTo(self.markView);
        make.left.equalTo(self.markView.mas_right).offset(8);
    }];
    
    [self.cardBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.equalTo(self.markView);
        make.left.equalTo(self.markLabel.mas_right).offset(8);
        make.width.mas_equalTo(65);
        make.height.mas_equalTo(20);
    }];
    
    [self.detailBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.equalTo(self.markView);
        make.left.equalTo(self.cardBtn.mas_right).offset(15);
        make.right.equalTo(self.bottomView).offset(-15);
        make.width.mas_equalTo(65);
        make.height.mas_equalTo(20);
    }];
    
    CGFloat width = (kScreenWidth - 15 *2) /5.0;
    [self.label1 mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.equalTo(self.bottomView).offset(15);
        make.top.equalTo(self.markView.mas_bottom).offset(20);
        make.width.mas_equalTo(width);
        make.bottom.equalTo(self.bottomView).offset(-15);
    }];
    
    [self.label2 mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.equalTo(self.label1.mas_right).offset(0);
        make.top.equalTo(self.markView.mas_bottom).offset(20);
        make.width.mas_equalTo(width);
    }];
    
    [self.label3 mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.equalTo(self.label2.mas_right).offset(0);
        make.top.equalTo(self.markView.mas_bottom).offset(20);
        make.width.mas_equalTo(width);
    }];
    
    [self.label4 mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.equalTo(self.label3.mas_right).offset(0);
        make.top.equalTo(self.markView.mas_bottom).offset(20);
        make.width.mas_equalTo(width);
    }];
    
    [self.label5 mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.equalTo(self.label4.mas_right).offset(0);
        make.top.equalTo(self.markView.mas_bottom).offset(20);
        make.width.mas_equalTo(width);
    }];
    
    
}

#pragma mark -- lazyLoad

-(UIView *)bottomView
{
    if (!_bottomView) {
        _bottomView = [UIView new];
        _bottomView.backgroundColor = UIColorFromHex(kColorWhite);
//        [_bottomView addTopLine];
    }
    return _bottomView;
}

- (UIView *)lineView
{
    if (!_lineView) {
        _lineView = [UIView new];
        _lineView.backgroundColor = UIColorFromHex(kColorBG);
        [_lineView addTopLine];
        [_lineView addBottomLine];
    }
    return _lineView;
}

-(UILabel *)infoLabel
{
    if (!_infoLabel) {
        _infoLabel = [UILabel new];
        _infoLabel.textColor = UIColorFromHex(kColorMain);
        _infoLabel.font = UIFontSize(14);
        
    }
    return _infoLabel;
}

-(UIView *)line
{
    if (!_line) {
        _line = [UIView new];
        _line.backgroundColor = UIColorFromHex(kColorLine);
    }
    return _line;
}

-(UIView *)markView
{
    if (!_markView) {
        _markView = [UIView new];
        _markView.backgroundColor = UIColorFromHex(kColorMain);
    }
    return _markView;
}

-(UILabel *)markLabel
{
    if (!_markLabel) {
        _markLabel = [UILabel new];
        _markLabel.textColor = UIColorFromHex(0x000000);
        _markLabel.font = UIFontSize(14);
    }
    return _markLabel;
}

-(UIButton *)cardBtn
{
    if (!_cardBtn) {
        _cardBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _cardBtn.backgroundColor = UIColorFromHex(kColorMain);
        [_cardBtn setTitle:@"查看答题卡" forState:UIControlStateNormal];
        [_cardBtn setTitleColor:UIColorFromHex(kColorWhite) forState:UIControlStateNormal];
        _cardBtn.titleLabel.font = UIFontSize(11);
        _cardBtn.layer.cornerRadius = 5;
        _cardBtn.layer.masksToBounds = YES;
    }
    return _cardBtn;
}

-(UIButton *)detailBtn
{
    if (!_detailBtn) {
        _detailBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _detailBtn.backgroundColor = UIColorFromHex(kColorMain);
        [_detailBtn setTitle:@"试题详情" forState:UIControlStateNormal];
        [_detailBtn setTitleColor:UIColorFromHex(kColorWhite) forState:UIControlStateNormal];
        _detailBtn.titleLabel.font = UIFontSize(11);
        _detailBtn.layer.cornerRadius = 5;
        _detailBtn.layer.masksToBounds = YES;
    }
    return _detailBtn;
}

-(UILabel *)label1
{
    if (!_label1) {
        _label1 = [UILabel new];
        _label1.text = @"题号";
        _label1.textColor = UIColorFromHex(0x000000);
        _label1.font = UIFontSize(13);
        _label1.textAlignment = NSTextAlignmentLeft;
    }
    return _label1;
}

-(UILabel *)label2
{
    if (!_label2) {
        _label2 = [UILabel new];
        _label2.text = @"题型";
        _label2.textColor = UIColorFromHex(0x000000);
        _label2.font = UIFontSize(13);
        _label2.textAlignment = NSTextAlignmentCenter;
    }
    return _label2;
}

-(UILabel *)label3
{
    if (!_label3) {
        _label3 = [UILabel new];
        _label3.text = @"答案";
        _label3.textColor = UIColorFromHex(0x000000);
        _label3.font = UIFontSize(13);
        _label3.textAlignment = NSTextAlignmentCenter;
    }
    return _label3;
}


-(UILabel *)label4
{
    if (!_label4) {
        _label4 = [UILabel new];
        _label4.text = @"得分/满分";
        _label4.textColor = UIColorFromHex(0x000000);
        _label4.font = UIFontSize(13);
        _label4.textAlignment = NSTextAlignmentCenter;
    }
    return _label4;
}

-(UILabel *)label5
{
    if (!_label5) {
        _label5 = [UILabel new];
        _label5.text = @"更多";
        _label5.textColor = UIColorFromHex(0x000000);
        _label5.font = UIFontSize(13);
        _label5.textAlignment = NSTextAlignmentRight;
    }
    return _label5;
}

@end
